package com.jsmtr.rms.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jsmtr.rms.entity.*;
import com.jsmtr.rms.utils.StringTools;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.jsmtr.rms.service.IDoResumeService;
import com.jsmtr.rms.service.IRecommendService;
import com.jsmtr.rms.service.IDoZZService;
import com.jsmtr.rms.service.ISchoolService;
import com.jsmtr.rms.service.IUtilService;
import com.jsmtr.rms.utils.PhoneTools;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/Do/ZZEmploy")
public class DoZZEmployController {

    @Resource
    private IUtilService utilService;
    @Resource
    private IRecommendService recommendService;
    @Resource
    private ISchoolService schoolService;
    @Resource
    private IDoZZService doZZService;
    @Resource
    private IDoResumeService doResumeService;


    //[start] 查询毕业生信息

    //首页
    @RequestMapping("/")
    public String Index(HttpServletRequest request, Model model) {
        try {
            model.addAttribute("path", request.getContextPath());
            String pid = request.getParameter("pid").trim();
            String fid = request.getParameter("fid").trim();
            String deptcode = request.getParameter("deptcode").trim();

            model.addAttribute("pid", pid);
            model.addAttribute("fid", fid);
            model.addAttribute("deptcode", deptcode);
            model.addAttribute("fpath", utilService.getConfig("path"));

            StringBuilder str = new StringBuilder();
            List<HRSchoolUsers> schools = schoolService.getSchools();
            for (HRSchoolUsers school : schools) {
                str.append("<option value='" + school.getId() + "'>" + school.getUname() + "</option>");
            }
            model.addAttribute("school", str);

            List<BaseConfig> configs = utilService.getConfigs("dzmb");
            StringBuilder str1 = new StringBuilder();
            for (BaseConfig config : configs) {
                str1.append("<option value='" + config.getCont() + "'>" + config.getCont() + "</option>");
            }
            model.addAttribute("address", str1);

            List<String> dates = doZZService.getBdTimeList(pid, deptcode);
            StringBuilder str2 = new StringBuilder();
            for (String date : dates) {
                str2.append("<option value='" + date + "'>" + (date == null ? "" : date) + "</option>");
            }
            model.addAttribute("bdtime", str2);

            List<BaseConfig> _configs = utilService.getConfigs("dxmb");
            StringBuilder str3 = new StringBuilder();
            for (BaseConfig _config : _configs) {
                str3.append("<option value='" + _config.getCode() + "'>" + _config.getName() + "</option>");
            }
            model.addAttribute("dxmb", str3);

            //招聘岗位
            List<ProjectInfoJobs> projectJobs=utilService.getProjectJobs(pid);
            model.addAttribute("jobs",projectJobs);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Do/ZZCampus/Employ/index";
    }

    @SuppressWarnings("unchecked")
    @RequestMapping("/getusers")
    public void getusers(HttpServletRequest request, HttpServletResponse response, HRZZUser user) {
        try {
            int perpage = Integer.parseInt(request.getParameter("perpage"));
            int page = Integer.parseInt(request.getParameter("page"));
            String flowid = request.getParameter("flowid").trim();
            user.setPath("/" + flowid + "/");
            Map<String, Object> _map = new HashMap<String, Object>();
            _map.put("agefrom", request.getParameter("agefrom")==null?"":request.getParameter("agefrom").trim());
            _map.put("ageto", request.getParameter("ageto")==null?"":request.getParameter("ageto").trim());
            _map.put("heightfrom", request.getParameter("heightfrom")==null?"":request.getParameter("heightfrom").trim());
            _map.put("heightto", request.getParameter("heightto")==null?"":request.getParameter("heightto").trim());
            _map.put("rcount",request.getParameter("graduationyear")==null?"":request.getParameter("graduationyear").trim());
            _map.put("ischangejob",request.getParameter("ischangejob"));
           // Map<String, Object> map = recommendService.getUsers(page, perpage, user,_map);
            Map<String, Object> map = recommendService.getUserMap(page, perpage, user,_map);
            StringBuilder result = new StringBuilder();
            double pageCount = (Double) map.get("pageCount");
            double allcount = (Double) map.get("count");

            if (pageCount != 0) {
//                Object object = map.get("list");
                List<Map<String,Object>> object=(List<Map<String,Object>>)map.get("list");
                int num = 0;
                /*for (HRZZUser _user : (List<HRZZUser>) object) {
                    result.append("<tr><td><input type=\"checkbox\" name='uid' value='" + _user.getId() + "' id='cb_" + _user.getId() + "' /></td>");
                    result.append("<td>" + (perpage * (page - 1) + num + 1) + "</td>");
                    result.append("<td class='link'><a target='_blank' href='"
                            + request.getContextPath() + "/Do/SZResume/View?id="
                            + _user.getId() + "'>" + _user.getName()
                            + "</a></td>");//简历ID和HRZZUser的ID相同
                    result.append("<td>" + _user.getGender() + "</td>");
                    result.append("<td>" + _user.getCode() + "</td>");
                    result.append("<td>" + (_user.getGwname() == null ? "" : _user.getGwname()) + "</td>");
                    result.append("<td>" + _user.getDeptname() + "<input type='hidden' name='user[" + num + "].id' value='" + _user.getId() + "' /></td>");
                    result.append("<td>" + (_user.getBdtime() == null ? "" : _user.getBdtime()) + "</td>");
                    result.append("<td>" + (_user.getBdaddress() == null ? "" : _user.getBdaddress()) + "</td>");
                    result.append("<td>" + (_user.getBdlxr() == null ? "" : (_user.getBdlxr() + " " + _user.getBdlxdh())) + "</td>");
                    result.append("<td>" + _user.getBdmsg() + "</td>");
                    result.append("<td>" + _user.getBdstate() + "</td>");
                    if (_user.getOp8().equals("未公布")) {
                        result.append("<td class='true'><span>" + _user.getOp8() + "</span></td>");
                    } else {
                        result.append("<td class='false'><span>" + _user.getOp8() + "</span></td>");
                    }
                    if (_user.getFqstate().equals("已放弃")
                            && _user.getFqfid().equals(flowid)) {
                        result.append("<td class='yfq'><span>已放弃</span></td></tr>");
                    } else {
                        if (_user.getBdstate().equals("已报到")) {
                            result.append("<td class='false'><span>已完成</span></td></tr>");
                        } else {
                            result.append("<td class='true'><span>未完成</span></td></tr>");
                        }
                    }

                    num++;
                }*/
                for (Map<String,Object> _user :  object) {
                    result.append("<tr><td><input type=\"checkbox\" name='uid' value='" + _user.get("ID") + "' id='cb_" + _user.get("ID") + "' /></td>");
                    result.append("<td>" + (perpage * (page - 1) + num + 1) + "</td>");
                    result.append("<td class='link'><a target='_blank' href='"
                            + request.getContextPath() + "/UserResume/ViewDResume?id="
                            + _user.get("ID") + "'>" + _user.get("NAME")
                            + "</a></td>");//简历ID和HRZZUser的ID相同
                    result.append("<td>" + _user.get("GENDER") + "</td>");
                    result.append("<td>" + _user.get("CODE") + "</td>");
                    result.append("<td>" + (_user.get("JOB") == null ? "" : _user.get("JOB")) + "</td>");
                    result.append("<td>" + _user.get("DEPTNAME") + "<input type='hidden' name='user[" + num + "].id' value='" + _user.get("ID") + "' /></td>");
                    result.append("<td>" + (_user.get("BDTIME") == null ? "" : _user.get("BDTIME")) + "</td>");
                    result.append("<td>" + (_user.get("BDADDRESS") == null ? "" : _user.get("BDADDRESS")) + "</td>");
                    result.append("<td>" + (_user.get("BDLXR") == null ? "" : (_user.get("BDLXR") + " " + _user.get("BDLXDH"))) + "</td>");
                    result.append("<td>" + _user.get("BDMSG") + "</td>");
                    result.append("<td>" + _user.get("BDSTATE") + "</td>");
                    if (_user.get("OP8").equals("未公布")) {
                        result.append("<td class='true'><span>" + _user.get("OP8") + "</span></td>");
                    } else {
                        result.append("<td class='false'><span>" + _user.get("OP8") + "</span></td>");
                    }
                    /*if (_user.get("FQSTATE").equals("已放弃")
                            && _user.get("FQFID").equals(flowid)) {
                        result.append("<td class='yfq'><span>已放弃</span></td></tr>");
                    } else {
                        if (_user.get("BDSTATE").equals("已报到")) {
                            result.append("<td class='false'><span>已完成</span></td></tr>");
                        } else {
                            result.append("<td class='true'><span>未完成</span></td></tr>");
                        }
                    }*/
                    result.append("<td>");
                    if (_user.get("FQSTATE").equals("已放弃") && _user.get("FQFID").equals(flowid)) {
                        // result.append("<td class='yfq'><span>已放弃</span></td></tr>");
                        result.append("<span class='layui-badge layui-bg-gray' title='已放弃'>弃</span>");
                    } else {

                        if (_user.get("BDSTATE") == null) {
                            // result.append("<td class='true'><span>未完成</td></tr>");
                            result.append("<span class='layui-badge layui-bg-orange' title='未完成'>未</span>");
                        } else {
                            if (_user.get("BDSTATE").equals("已通过")
                                    || (_user.get("SXSTATE").equals("未安排") && !_user.get("FID").equals(flowid))) {
                                //result.append("<td class='true'><span>未完成</td></tr>");
                                result.append("<span class='layui-badge layui-bg-green' title='已完成'>完</span>");
                            } else if (_user.get("BDSTATE").equals("未通过")||_user.get("BDSTATE").equals("不通过")||_user.get("BDSTATE").equals("不合格")||_user.get("BDSTATE").equals("未参加")) {
                                result.append("<td class='false'><span>已完成</td></tr>");

                                // result.append("<span class='layui-badge layui-bg-orange' title='未完成'>未</span>");
                            } else {
                                if (_user.get("FID").equals(flowid)) {
                                    // result.append("<td class='true'><span>未完成</td></tr>");
                                    result.append("<span class='layui-badge layui-bg-orange' title='未完成'>未</span>");
                                } else {
                                    //result.append("<td class='false'><span>已完成</td></tr>");
                                    result.append("<span class='layui-badge layui-bg-green' title='已完成'>完</span>");
                                }
                            }
                        }
                    }
                    if (_user.get("NRID") != null) {
                        result.append("<span class='layui-badge layui-bg-blue' title='转岗(原岗位:"+_user.get("NJNAME")+")'>岗</span>");
                        //result.append("<td class='ytj'><span title='" +  _user.get("NJNAME") + "'>已推荐</span></td></tr>");
                    }
                    result.append("</td>");
                    result.append("</tr>");
                    num++;
                }

            } else {
                result.append("<tr><td colspan='16'>未找到符合条件的数据</td></tr>");
            }
            result.append("<input type='hidden' id='pageCount' value='" + pageCount + "' />");
            result.append("<input type='hidden' id='allCount' value='" + allcount + "' />");
            utilService.printTextResult(result.toString(), response);
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printTextResult("<tr><td colspan='14'>读取数据失败</td></tr><input type='hidden' id='pageCount' value='0' /><input type='hidden' id='allCount' value='0' />", response);
        }

    }
    //[end]
    @ResponseBody
    @RequestMapping(value = "/getZzEmployListLayuiJson", method = RequestMethod.GET)
    public LayuiDataTableResultBean getZzEmployListLayuiJson(HttpServletRequest request, HttpServletResponse response, HRZZUser user) {
        try {
            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));
            String flowid = request.getParameter("flowid").trim();
            user.setPath("/" + flowid + "/");
            Map<String, Object> _map = new HashMap<String, Object>();
            _map.put("agefrom", request.getParameter("agefrom")==null?"":request.getParameter("agefrom").trim());
            _map.put("ageto", request.getParameter("ageto")==null?"":request.getParameter("ageto").trim());
            _map.put("heightfrom", request.getParameter("heightfrom")==null?"":request.getParameter("heightfrom").trim());
            _map.put("heightto", request.getParameter("heightto")==null?"":request.getParameter("heightto").trim());
            _map.put("rcount",request.getParameter("graduationyear")==null?"":request.getParameter("graduationyear").trim());
            _map.put("ischangejob",request.getParameter("ischangejob"));
            // Map<String, Object> map = recommendService.getUsers(page, perpage, user,_map);
            Map<String, Object> map = recommendService.getUserMap(page, limit, user,_map);

            double pageCount = (Double) map.get("pageCount");
            double allcount = (Double) map.get("count");

            JSONArray jsonArray = new JSONArray();
            int num = 1;
            if (pageCount != 0) {
                List<Map<String,Object>> object=(List<Map<String,Object>>)map.get("list");
                for (Map<String,Object> _user :  object) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("id_cb", "cb_" + _user.get("ID") );
                    jsonObject.put("id", limit * (page - 1) + num);
                    jsonObject.put("NAME", _user.get("NAME"));
                    jsonObject.put("ContextPath", request.getContextPath() + "/UserResume/ViewDResume?id=" + _user.get("ID") );
                    jsonObject.put("SEXNAME", _user.get("GENDER") );
                    jsonObject.put("CARDNO", _user.get("CODE") );
                    jsonObject.put("JOB", (_user.get("JOB") == null ? "" : _user.get("JOB")));
                    jsonObject.put("BDTIME",(_user.get("BDTIME") == null ? "" : _user.get("BDTIME")));
                    jsonObject.put("BDADRESS", (_user.get("BDADDRESS") == null ? "" : _user.get("BDADDRESS")) );
                    jsonObject.put("BDLXRs", (_user.get("BDLXR") == null ? "" : (_user.get("BDLXR") + " " + _user.get("BDLXDH"))));
                    jsonObject.put("BDMSG", _user.get("BDMSG") );
                    jsonObject.put("STATEb", _user.get("OP8"));

                    jsonObject.put("FQSTATE", _user.get("FQSTATE"));
                    jsonObject.put("FQFID", _user.get("FQFID"));
                    jsonObject.put("FID", _user.get("FID"));
                    jsonObject.put("BDSTATE", _user.get("BDSTATE"));

                    if (_user.get("FQSTATE").equals("已放弃") && _user.get("FQFID").equals(flowid)) {
                        jsonObject.put("STATEc", "弃");
                    } else {

                        if (_user.get("BDSTATE") == null) {
                            jsonObject.put("STATEc", "未");
                        } else {
                            if (_user.get("BDSTATE").equals("已通过") || (_user.get("SXSTATE").equals("未安排") && !_user.get("FID").equals(flowid))) {
                                jsonObject.put("STATEc", "完");
                            } else if (_user.get("BDSTATE").equals("未通过")||_user.get("BDSTATE").equals("不通过")||_user.get("BDSTATE").equals("不合格")||_user.get("BDSTATE").equals("未参加")) {
                                jsonObject.put("STATEc", "完");
                            } else {
                                if (_user.get("FID").equals(flowid)) {
                                    jsonObject.put("STATEc", "未");
                                } else {
                                    jsonObject.put("STATEc", "完");
                                }
                            }
                        }
                    }
                    if (StringTools.trimNotEmpty(_user.get("NRID"))){
                        jsonObject.put("NJNAME", _user.get("NJNAME"));
                        jsonObject.put("STATEd", "岗");
                        jsonObject.put("NRID", _user.get("NRID"));
                    }else
                        jsonObject.put("NRID", "");

                    jsonObject.put("arrange", _user.get("BDARRANGE"));

                    jsonArray.add(jsonObject);
                    num++;
                }
            }

            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            result.setCode(0);
            result.setMsg("success");
            result.setCount((int) allcount);
            result.setData(jsonArray);

            return result;
        } catch (Exception e) {
            e.printStackTrace();

            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            result.setCount(-1);
            result.setMsg("err");
            return result;
        }
    }


    //[start] 报到安排

    @RequestMapping(value = "/PlanAction", method = RequestMethod.POST)
    public void PlanAction(HttpServletRequest request, HttpServletResponse response, HRZZUser user) {
        try {
            String[] uids = request.getParameterValues("uid");
            if (uids == null) {
                utilService.printJsonResult(false, "请选择报到人员!", "no", response);
            } else {
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码
                String fid = request.getParameter("path").trim();//招聘流程ID
                BaseUser cuser = utilService.getSessionUser(request);
                if (cuser.getUdept().equals(deptcode)) {
                    //流程是否结束
                    if (utilService.FlowIsDoing(fid)) {
                        List<HRZZUser> editlist = new ArrayList<HRZZUser>();
                        for (String uid : uids) {
                            HRZZUser _user = recommendService.getViewUser(uid);
                            if (_user.getBdmsg().equals("未发通知")
                                    && _user.getFqstate().equals("未放弃")
                                    && _user.getFid().equals(fid)) {
                                _user.setBdtime(user.getBdtime());
                                _user.setBdaddress(user.getBdaddress());
                                _user.setBdlxr(user.getBdlxr());
                                _user.setBdlxdh(user.getBdlxdh());
                                editlist.add(_user);
                            }
                        }
                        if (editlist.size() > 0) {
                            utilService.editList(editlist);
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "当前选中信息不能执行此操作！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败!", "no", response);
        }
    }

    //[end]

    //[start] 发布报到通知

    @RequestMapping(value = "/MsgAction", method = RequestMethod.POST)
    public void MsgAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String pid = request.getParameter("pid").trim();//招聘方案ID
            String fid = request.getParameter("fid").trim();//招聘流程ID
            String deptcode = request.getParameter("deptcode").trim();//责任部门编码

            BaseUser cuser = utilService.getSessionUser(request);
            if (cuser.getUdept().equals(deptcode)) {
                //流程是否结束
                if (utilService.FlowIsDoing(fid)) {
                    List<HRZZUser> editlist = new ArrayList<HRZZUser>();
                    String bdtime = request.getParameter("bdtime").trim();
                    String dxnr = request.getParameter("dxnr").trim();

                    List<Map<String, String>> msgs = new ArrayList<Map<String, String>>();

                    List<HRZZUser> users = doZZService.getBdUsers(pid, deptcode, bdtime);
                    for (HRZZUser user : users) {
                        if (user.getBdmsg().equals("未发通知")
                                && user.getFqstate().equals("未放弃")
                                && user.getFid().equals(fid)) {
                            user.setBdmsg("已发通知");
                            editlist.add(user);

                            //-------------短信----------------
                            Map<String, String> _map = new HashMap<String, String>();
                            _map.put("tel", user.getTel());
                            _map.put("cont", dxnr.replace("{姓名}", user.getName()).replace("{时间}", user.getBdtime()).replace("{地点}", user.getBdaddress()));
                            msgs.add(_map);

                        }
                    }

                    if (editlist.size() > 0) {
                        utilService.editList(editlist);
                        BaseMessageConfig messageConfig=utilService.getMessageConfig();
                        // 发送短信
                        if (PhoneTools.sendMsg(msgs,messageConfig.getUsername(),messageConfig.getPassword(),messageConfig.getHost())) {
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "短信发送失败！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "无可执行此操作的信息！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }
    }

    //[end]

    //[start] 获得短信模版内容

    @RequestMapping("/getMsg")
    public void getMsgCont(HttpServletRequest request, HttpServletResponse response) {
        try {
            String msg = utilService.getConfig(request.getParameter("code").trim());
            utilService.printTextResult(msg, response);
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printTextResult("", response);
        }
    }

    //[end]

    //[start] 提交报到结果

    @SuppressWarnings({"unchecked", "rawtypes"})
    @RequestMapping(value = "/RAction", method = RequestMethod.POST)
    public void RAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String pid = request.getParameter("pid").trim();//招聘方案ID
            String fid = request.getParameter("fid").trim();//招聘流程ID
            String deptcode = request.getParameter("deptcode").trim();//责任部门编码
            String[] ids = request.getParameterValues("id");

            BaseUser cuser = utilService.getSessionUser(request);
            if (cuser.getUdept().equals(deptcode)) {
                //流程是否结束
                if (utilService.FlowIsDoing(fid)) {
                    Date time = new Date();
                    List editlist = new ArrayList();
                    List<HRZZUser> users = doZZService.getUsers(ids);
                    for (HRZZUser user : users) {
                        HRZZUser usr = recommendService.getViewUser(user.getId());
                        if (usr.getDeptcode().equals(cuser.getUdept())
                                && usr.getFqstate().equals("未放弃")
                                && usr.getBdstate().equals("未报到")
                                && usr.getFid().equals(fid)) {
                            usr.setBdstate("已报到");
                            usr.setBddate(time);
                            usr.setBduid(cuser.getId());
                            usr.setBduname(cuser.getUname());

                            editlist.add(usr);
                        }
                    }
                    if (editlist.size() > 0) {
                        utilService.editList(editlist);
                        utilService.printJsonResult(true, "操作成功！", "no", response);
                    } else {
                        utilService.printJsonResult(false, "当前信息不能执行此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }
    }

    //[end]

    //[start] 导出人员信息

    /**
     * 导出通过应聘的人员信息
     *
     * @param request
     * @param response
     */
    @RequestMapping(value = "/OutUserInfo")
    public void OutUserInfo(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("application/vnd.ms-excel");
        String codedFileName = null;
        OutputStream fOut = null;
        try {
            String pid = request.getParameter("pid").trim();//招聘方案ID

            codedFileName = java.net.URLEncoder.encode("人员信息", "UTF-8");
            response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls");
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet();

            //[start] 表头

            HSSFRow headrow = sheet.createRow(0);//创建一行
            HSSFCell headcel0 = headrow.createCell(0);
            headcel0.setCellValue(new HSSFRichTextString("工号"));
            HSSFCell headcel1 = headrow.createCell(1);
            headcel1.setCellValue(new HSSFRichTextString("姓名"));
            HSSFCell headcel2 = headrow.createCell(2);
            headcel2.setCellValue(new HSSFRichTextString("名族"));
            HSSFCell headcel3 = headrow.createCell(3);
            headcel3.setCellValue(new HSSFRichTextString("性别"));
            HSSFCell headcel4 = headrow.createCell(4);
            headcel4.setCellValue(new HSSFRichTextString("手机"));
            HSSFCell headcel5 = headrow.createCell(5);
            headcel5.setCellValue(new HSSFRichTextString("应聘职位"));
            HSSFCell headcel6 = headrow.createCell(6);
            headcel6.setCellValue(new HSSFRichTextString("证件号码"));
            HSSFCell headcel7 = headrow.createCell(7);
            headcel7.setCellValue(new HSSFRichTextString("最高学历"));
            HSSFCell headcel8 = headrow.createCell(8);
            headcel8.setCellValue(new HSSFRichTextString("最高学位"));
            HSSFCell headcel9 = headrow.createCell(9);
            headcel9.setCellValue(new HSSFRichTextString("出生日期"));
            HSSFCell headcel10 = headrow.createCell(10);
            headcel10.setCellValue(new HSSFRichTextString("现居住地"));
            HSSFCell headcel11 = headrow.createCell(11);
            headcel11.setCellValue(new HSSFRichTextString("身份证所在地"));
            HSSFCell headcel12 = headrow.createCell(12);
            headcel12.setCellValue(new HSSFRichTextString("户口所在地"));
            HSSFCell headcel13 = headrow.createCell(13);
            headcel13.setCellValue(new HSSFRichTextString("身高"));
            HSSFCell headcel14 = headrow.createCell(14);
            headcel14.setCellValue(new HSSFRichTextString("婚姻状况"));
            HSSFCell headcel15 = headrow.createCell(15);
            headcel15.setCellValue(new HSSFRichTextString("公司名称"));
            HSSFCell headcel16 = headrow.createCell(16);
            headcel16.setCellValue(new HSSFRichTextString("开始时间"));
            HSSFCell headcel17 = headrow.createCell(17);
            headcel17.setCellValue(new HSSFRichTextString("结束时间"));
            HSSFCell headcel18 = headrow.createCell(18);
            headcel18.setCellValue(new HSSFRichTextString("职位名称"));
            HSSFCell headcel19 = headrow.createCell(19);
            headcel19.setCellValue(new HSSFRichTextString("离职/转岗原因"));
            HSSFCell headcel20 = headrow.createCell(20);
            headcel20.setCellValue(new HSSFRichTextString("工作地点"));
            HSSFCell headcel21 = headrow.createCell(21);
            headcel21.setCellValue(new HSSFRichTextString("开始时间"));
            HSSFCell headcel22 = headrow.createCell(22);
            headcel22.setCellValue(new HSSFRichTextString("结束时间"));
            HSSFCell headcel23 = headrow.createCell(23);
            headcel23.setCellValue(new HSSFRichTextString("就读院校"));
            HSSFCell headcel24 = headrow.createCell(24);
            headcel24.setCellValue(new HSSFRichTextString("专业名称"));
            HSSFCell headcel25 = headrow.createCell(25);
            headcel25.setCellValue(new HSSFRichTextString("学历"));
            HSSFCell headcel26 = headrow.createCell(26);
            headcel26.setCellValue(new HSSFRichTextString("学位"));
            HSSFCell headcel27 = headrow.createCell(27);
            headcel27.setCellValue(new HSSFRichTextString("专业技术职务类别"));
            HSSFCell headcel28 = headrow.createCell(28);
            headcel28.setCellValue(new HSSFRichTextString("专业技术职务专业"));
            HSSFCell headcel29 = headrow.createCell(29);
            headcel29.setCellValue(new HSSFRichTextString("专业技术职务级别"));
            HSSFCell headcel30 = headrow.createCell(30);
            headcel30.setCellValue(new HSSFRichTextString("专业技术职务取得时间"));
            HSSFCell headcel31 = headrow.createCell(31);
            headcel31.setCellValue(new HSSFRichTextString("职业资格证工种"));
            HSSFCell headcel32 = headrow.createCell(32);
            headcel32.setCellValue(new HSSFRichTextString("职业资格证技能等级"));
            HSSFCell headcel33 = headrow.createCell(33);
            headcel33.setCellValue(new HSSFRichTextString("职业资格证取得时间"));
            HSSFCell headcel34 = headrow.createCell(34);
            headcel34.setCellValue(new HSSFRichTextString("其他资格证名称"));
            HSSFCell headcel35 = headrow.createCell(35);
            headcel35.setCellValue(new HSSFRichTextString("其他资格证类型"));
            HSSFCell headcel36 = headrow.createCell(36);
            headcel36.setCellValue(new HSSFRichTextString("其他资格证发证机构"));
            HSSFCell headcel37 = headrow.createCell(37);
            headcel37.setCellValue(new HSSFRichTextString("其他资格证取得时间"));

            //[end]

            List<DUserResume> resumes = doResumeService.getResumes(pid);
            java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy年MM月dd日");

            int i = 1;
            for (DUserResume resume : resumes) {
                HSSFRow row = sheet.createRow(i);//创建一行

                HSSFCell cell1 = row.createCell(1);//创建一列
                //cell1.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell1.setCellType(CellType.STRING);
                cell1.setCellValue(new HSSFRichTextString(resume.getName()));

                HSSFCell cell2 = row.createCell(2);//创建一列
               // cell2.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell2.setCellType(CellType.STRING);
                cell2.setCellValue(new HSSFRichTextString(resume.getMzname()));

                HSSFCell cell3 = row.createCell(3);//创建一列
               // cell3.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell3.setCellType(CellType.STRING);
                cell3.setCellValue(new HSSFRichTextString(resume.getSexname()));

                HSSFCell cell4 = row.createCell(4);//创建一列
                //cell4.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell4.setCellType(CellType.STRING);
                cell4.setCellValue(new HSSFRichTextString(resume.getTel()));

                HSSFCell cell6 = row.createCell(6);//创建一列
               // cell6.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell6.setCellType(CellType.STRING);
                cell6.setCellValue(new HSSFRichTextString(resume.getCardno()));

                HSSFCell cell7 = row.createCell(7);//创建一列
               // cell7.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell7.setCellType(CellType.STRING);
                cell7.setCellValue(new HSSFRichTextString(resume.getEducationname()));

                HSSFCell cell8 = row.createCell(8);//创建一列
               // cell8.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell8.setCellType(CellType.STRING);

                HSSFCell cell9 = row.createCell(9);//创建一列
                //cell9.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell9.setCellType(CellType.STRING);
                cell9.setCellValue(new HSSFRichTextString(df.format(resume.getBirthday())));

                HSSFCell cell10 = row.createCell(10);//创建一列
               // cell10.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell10.setCellType(CellType.STRING);
                cell10.setCellValue(new HSSFRichTextString(resume.getNowaddress()));

                HSSFCell cell12 = row.createCell(12);//创建一列
                //cell12.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell12.setCellType(CellType.STRING);
                cell12.setCellValue(new HSSFRichTextString(resume.getHukouaddress()));

                HSSFCell cell13 = row.createCell(13);//创建一列
               // cell13.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell13.setCellType(CellType.STRING);
                cell13.setCellValue(new HSSFRichTextString(resume.getHeight().toString()));

                HSSFCell cell14 = row.createCell(14);//创建一列
               // cell14.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell14.setCellType(CellType.STRING);
                cell14.setCellValue(new HSSFRichTextString(resume.getMname()));

                //工作经验
                List<DUserWorkExperience> works = doResumeService.getUserWorkExperience(resume.getId());
                if (works.size() > 0) {
                    HSSFCell cell15 = row.createCell(15);//创建一列
                   // cell15.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell15.setCellType(CellType.STRING);
                    cell15.setCellValue(new HSSFRichTextString(works.get(0).getCompanyname()));

                    HSSFCell cell16 = row.createCell(16);//创建一列
                   // cell16.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell16.setCellType(CellType.STRING);
                    cell16.setCellValue(new HSSFRichTextString(df.format(works.get(0).getStarttime())));

                    HSSFCell cell17 = row.createCell(17);//创建一列
                    //cell17.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell17.setCellType(CellType.STRING);
                    cell17.setCellValue(new HSSFRichTextString(df.format(works.get(0).getEndtime())));

                    HSSFCell cell18 = row.createCell(18);//创建一列
                   // cell18.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell18.setCellType(CellType.STRING);
                    cell18.setCellValue(new HSSFRichTextString(works.get(0).getPosition()));

                    HSSFCell cell19 = row.createCell(19);//创建一列
                   // cell19.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell19.setCellType(CellType.STRING);
                    cell19.setCellValue(new HSSFRichTextString((works.get(0).getReason() == null ? "" : works.get(0).getReason())));
                }

                //教育背景
                List<DUserEducation> edus = doResumeService.getUserEducation(resume.getId());
                if (edus.size() > 0) {
                    HSSFCell cell21 = row.createCell(21);//创建一列
                    //cell21.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell21.setCellType(CellType.STRING);
                    cell21.setCellValue(new HSSFRichTextString(df.format(edus.get(0).getStarttime())));

                    HSSFCell cell22 = row.createCell(22);//创建一列
                   // cell22.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell22.setCellType(CellType.STRING);
                    cell22.setCellValue(new HSSFRichTextString(df.format(edus.get(0).getEndtime())));

                    HSSFCell cell23 = row.createCell(23);//创建一列
                    //cell23.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell23.setCellType(CellType.STRING);
                    cell23.setCellValue(new HSSFRichTextString(edus.get(0).getSchoolname()));

                    HSSFCell cell24 = row.createCell(24);//创建一列
                    //cell24.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell24.setCellType(CellType.STRING);
                    cell24.setCellValue(new HSSFRichTextString(edus.get(0).getMajorname()));

                    HSSFCell cell25 = row.createCell(25);//创建一列
                    //cell25.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell25.setCellType(CellType.STRING);
                    cell25.setCellValue(new HSSFRichTextString(edus.get(0).getEducationname()));

                    HSSFCell cell26 = row.createCell(26);//创建一列
                    //cell26.setCellType(HSSFCell.CELL_TYPE_STRING);
                    cell26.setCellType(CellType.STRING);
                    cell26.setCellValue(new HSSFRichTextString(edus.get(0).getDegreename()));

                    cell8.setCellValue(new HSSFRichTextString(edus.get(0).getDegreename()));
                }

                HSSFCell cell27 = row.createCell(27);//创建一列
                //cell27.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell27.setCellType(CellType.STRING);
                cell27.setCellValue(new HSSFRichTextString((resume.getPosttypename() == null ? "" : resume.getPosttypename())));

                HSSFCell cell28 = row.createCell(28);//创建一列
               // cell28.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell28.setCellType(CellType.STRING);
                cell28.setCellValue(new HSSFRichTextString((resume.getPostspecialty() == null ? "" : resume.getPostspecialty())));

                HSSFCell cell29 = row.createCell(29);//创建一列
                //cell29.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell29.setCellType(CellType.STRING);
                cell29.setCellValue(new HSSFRichTextString((resume.getPostlevelname() == null ? "" : resume.getPostlevelname())));

                HSSFCell cell30 = row.createCell(30);//创建一列
                //cell30.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell30.setCellType(CellType.STRING);
                cell30.setCellValue(new HSSFRichTextString((resume.getPostgettime() == null ? "" : df.format(resume.getPostgettime()))));

                HSSFCell cell31 = row.createCell(31);//创建一列
                //cell31.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell31.setCellType(CellType.STRING);
                cell31.setCellValue(new HSSFRichTextString((resume.getQltype() == null ? "" : resume.getQltype())));

                HSSFCell cell32 = row.createCell(32);//创建一列
                //cell32.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell32.setCellType(CellType.STRING);
                cell32.setCellValue(new HSSFRichTextString((resume.getQllevelname() == null ? "" : resume.getQllevelname())));

                HSSFCell cell33 = row.createCell(33);//创建一列
                //cell33.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell33.setCellType(CellType.STRING);
                cell33.setCellValue(new HSSFRichTextString((resume.getQlgettime() == null ? "" : df.format(resume.getQlgettime()))));

                HSSFCell cell34 = row.createCell(34);//创建一列
                //cell34.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell34.setCellType(CellType.STRING);
                cell34.setCellValue(new HSSFRichTextString(resume.getOthname()));

                HSSFCell cell35 = row.createCell(35);//创建一列
                //cell35.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell35.setCellType(CellType.STRING);
                cell35.setCellValue(new HSSFRichTextString(resume.getOthtypename()));

                HSSFCell cell36 = row.createCell(36);//创建一列
               // cell36.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell36.setCellType(CellType.STRING);
                cell36.setCellValue(new HSSFRichTextString(resume.getOthorg()));

                HSSFCell cell37 = row.createCell(37);//创建一列
                //cell37.setCellType(HSSFCell.CELL_TYPE_STRING);
                cell37.setCellType(CellType.STRING);
                cell37.setCellValue(new HSSFRichTextString((resume.getOthdate() == null ? "" : df.format(resume.getOthdate()))));
                i++;
            }
            fOut = response.getOutputStream();
            workbook.write(fOut);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fOut.flush();
                fOut.close();
            } catch (IOException e) {
            }
        }
    }

    //[end]
}
